#include "FlatpakManager.h"
#include "ui_FlatpakManager.h"

#include <FlatpakUtil.h>

#include <QComboBox>
#include <QVBoxLayout>
#include <QLabel>
#include <QGroupBox>
#include <QPushButton>
#include <qgridlayout.h>


FlatpakManager::FlatpakManager(QWidget *parent) : QWidget(parent)
    , ui(new Ui::FlatpakManager)
{
    ui->setupUi(this);

    ui->flatpakRemoteButton->click();
}


void FlatpakManager::on_flatpakRemoteButton_clicked()
{
    ui->flatpakRemoteCombo->clear();
    auto repos = RepoManage::repositories();
    for (auto &repo : repos) {
        ui->flatpakRemoteCombo->addItem(QString("%1(%2)")
                                            .arg(repo["Name"]).arg(repo["Options"]), repo["Name"]);
    }
}

void FlatpakManager::on_flatpakRemoteCombo_currentTextChanged(const QString &arg1)
{
    QList<QMap<QString, QString>> repos = RepoManage::repositories();
    for (auto &repo : repos) {
        if (QString("%1(%2)").arg(repo["Name"]).arg(repo["Options"]).compare(arg1) == 0) {
            ui->title->setText(repo["Title"]);
            ui->url->setText(repo["Url"]);
            ui->options->setText(repo["Options"]);
            ui->collection->setText(repo["Collection_ID"]);
            ui->priority->setText(repo["Priority"]);
            ui->options->setText(repo["Options"]);
        }
    }
}

